package cn.edu.nju.software.cdiy.action.user.login;

import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;

import cn.edu.nju.software.cdiy.bean.Hcomment;
import cn.edu.nju.software.cdiy.bean.User;
import cn.edu.nju.software.cdiy.service.impl.HcommentServiceImpl;
import cn.edu.nju.software.cdiy.util.BusinessConstant;

import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class AddHcommentAction extends ActionSupport implements SessionAware, ServletResponseAware {

	private Map<String, Object> session;
	private HttpServletResponse response;
	private HcommentServiceImpl hcommentService;
	private Hcomment comment;

	@Override
	public void setSession(Map<String, Object> session) {
		this.session = session;
	}

	@Override
	public void setServletResponse(HttpServletResponse response) {
		this.response = response;
		this.response.setCharacterEncoding("UTF-8");
	}

	public void setHcommentService(HcommentServiceImpl hcommentService) {
		this.hcommentService = hcommentService;
	}
	
	public Hcomment getComment() {
		return comment;
	}

	public void setComment(Hcomment comment) {
		this.comment = comment;
	}

	public void add() throws Exception {
		User user = (User)session.get(BusinessConstant.S_USER);
		comment.setUserId(user.getId());
		comment.setUserName(user.getName());
		comment.setType(user.getType().getKey());
	    comment = hcommentService.saveHComment(comment);
	    response.getWriter().write("提交成功！");
	}

}
